SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS OFF
GO

/*
----------------------------------------------------------------------------------------------------

-- Created By:  ()
-- Purpose: Finds records in the Faq table passing nullable parameters
----------------------------------------------------------------------------------------------------
*/


CREATE PROCEDURE dbo.Faq_Find
(

	@SearchUsingOR bit   = null ,

	@Id int   = null ,

	@FullName nvarchar (100)  = null ,

	@Email nvarchar (50)  = null ,

	@Title nvarchar (50)  = null ,

	@Question nvarchar (500)  = null ,

	@Answer nvarchar (500)  = null ,

	@IsPublished bit   = null ,

	@ClientIp nvarchar (20)  = null ,

	@IsHot bit   = null ,

	@OrderIndex int   = null ,

	@AnsweredDate datetime   = null ,

	@AnsweredUser varchar (50)  = null ,

	@CreatedDate datetime   = null ,

	@UpdatedDate datetime   = null 
)
AS


				
  IF ISNULL(@SearchUsingOR, 0) <> 1
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Title]
	, [Question]
	, [Answer]
	, [IsPublished]
	, [ClientIp]
	, [IsHot]
	, [OrderIndex]
	, [AnsweredDate]
	, [AnsweredUser]
	, [CreatedDate]
	, [UpdatedDate]
    FROM
	[dbo].[Faq]
    WHERE 
	 ([Id] = @Id OR @Id IS NULL)
	AND ([FullName] = @FullName OR @FullName IS NULL)
	AND ([Email] = @Email OR @Email IS NULL)
	AND ([Title] = @Title OR @Title IS NULL)
	AND ([Question] = @Question OR @Question IS NULL)
	AND ([Answer] = @Answer OR @Answer IS NULL)
	AND ([IsPublished] = @IsPublished OR @IsPublished IS NULL)
	AND ([ClientIp] = @ClientIp OR @ClientIp IS NULL)
	AND ([IsHot] = @IsHot OR @IsHot IS NULL)
	AND ([OrderIndex] = @OrderIndex OR @OrderIndex IS NULL)
	AND ([AnsweredDate] = @AnsweredDate OR @AnsweredDate IS NULL)
	AND ([AnsweredUser] = @AnsweredUser OR @AnsweredUser IS NULL)
	AND ([CreatedDate] = @CreatedDate OR @CreatedDate IS NULL)
	AND ([UpdatedDate] = @UpdatedDate OR @UpdatedDate IS NULL)
						
  END
  ELSE
  BEGIN
    SELECT
	  [Id]
	, [FullName]
	, [Email]
	, [Title]
	, [Question]
	, [Answer]
	, [IsPublished]
	, [ClientIp]
	, [IsHot]
	, [OrderIndex]
	, [AnsweredDate]
	, [AnsweredUser]
	, [CreatedDate]
	, [UpdatedDate]
    FROM
	[dbo].[Faq]
    WHERE 
	 ([Id] = @Id AND @Id is not null)
	OR ([FullName] = @FullName AND @FullName is not null)
	OR ([Email] = @Email AND @Email is not null)
	OR ([Title] = @Title AND @Title is not null)
	OR ([Question] = @Question AND @Question is not null)
	OR ([Answer] = @Answer AND @Answer is not null)
	OR ([IsPublished] = @IsPublished AND @IsPublished is not null)
	OR ([ClientIp] = @ClientIp AND @ClientIp is not null)
	OR ([IsHot] = @IsHot AND @IsHot is not null)
	OR ([OrderIndex] = @OrderIndex AND @OrderIndex is not null)
	OR ([AnsweredDate] = @AnsweredDate AND @AnsweredDate is not null)
	OR ([AnsweredUser] = @AnsweredUser AND @AnsweredUser is not null)
	OR ([CreatedDate] = @CreatedDate AND @CreatedDate is not null)
	OR ([UpdatedDate] = @UpdatedDate AND @UpdatedDate is not null)
	SELECT @@ROWCOUNT			
  END
				

GO
